package com.Controller.Admin;

import com.Common.CodeMsg;
import com.Common.ResultModel;
import com.Model.Admin.SiteInfo;
import com.Service.Admin.SiteInfoService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Controller
public class SiteManagerController {

    @Autowired
    SiteInfoService siteInfoService;

    @RequestMapping(value = "/admin/SiteMnger")
    public String index() {
        return "admin/SiteManger";
    }

    @RequestMapping(value = "/admin/siteInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResultModel userInfo( SiteInfo siteInfo, BindingResult result) throws IOException {

        ResultModel resultModel;
        if (result.hasErrors()) {
            resultModel = new ResultModel(CodeMsg.param_is_empty.getIndex(), CodeMsg.param_is_empty.getName(), null);
            return resultModel;
        }

        PageInfo<SiteInfo> lst = siteInfoService.getSiteInfoByQuery(siteInfo);

        if (lst == null) {
            resultModel = new ResultModel(CodeMsg.nonData.getIndex(), CodeMsg.nonData.getName(), null);
        } else {
            resultModel = new ResultModel(CodeMsg.success.getIndex(), CodeMsg.success.getName(), lst.getList());
        }

        return resultModel;
    }


}
